/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.sprite.sheet;

import hapi.sprite.display.NMESpriteSheetDisplay;
import hapi.sprite.display.SpriteSheetDisplay;
import nme.display.BitmapData;
import nme.display.DisplayObjectContainer;
import nme.display.Graphics;
import nme.geom.Point;
import nme.geom.Rectangle;
import nme.display.Tilesheet;

class NMETileSpriteSheet extends SpriteSheetBase, implements SpriteSheet {

	var tile:Tilesheet;
	
	public function new(source:BitmapData, width:Int, height:Int) {
		super(source, width, height);
		this.tile = new Tilesheet(source);
		addTileRects();
	}
	
	function addTileRects() {
		for ( r in 0...rows) {
			for ( c in 0...cols) {
				tile.addTileRect(new Rectangle(c * width, r * height, width, height));
			}
		}
	}
	
	public function drawTilesOn(gfx:Graphics, xyids:Array<Float>) {
		gfx.drawTiles(tile, xyids);
	}
	
	public inline function drawSpriteOn(gfx:Graphics, xyid:Array<Float>):Void {
		gfx.drawTiles(tile, xyid);
	}
	
	public function createDisplay(?x:Float=0.0, ?y:Float=0.0):SpriteSheetDisplay {
		return createNMEDisplay(x, y);
	}
	
	public function createNMEDisplay(?x:Float = 0.0, ?y:Float = 0.0):NMESpriteSheetDisplay {
		return new NMESpriteSheetDisplay(this, x, y);
	}
}